import React from "react";

export default class ErrorBoundDary extends React.Component {
  state = {
    isError: false,
  };

  componentDidCatch() {
    this.setState({
      isError: true,
    });
  }

  render() {
    if (this.state.isError) {
      return <h2>发生错误，请检查代码</h2>;
    }
    return <div>{this.props.children}</div>;
  }
}
